package com.heima.user;

import com.heima.utils.common.MD5Utils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.mail.MailException;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.test.context.junit4.SpringRunner;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;

/**
 * @author Sun Chong
 * @date 2021/10/11 19:35
 */
@SpringBootTest
@RunWith(SpringRunner.class)
public class EmailSend {
    @Autowired
    JavaMailSenderImpl mailSender;

    @Test
    public void findByName(){
        try {
            String phone = "13511223456";
            MimeMessage message  = mailSender.createMimeMessage();
            MimeMessageHelper helper = new MimeMessageHelper(message, true);
            helper.setSubject("黑马头条官方邮件");
            helper.setText(" <html ><head></head><body><h1>这是一封激活邮件,激活请点击以下链接</h1><h3><a href='http://localhost:5001/user/api/v1/login/Confirm/"+phone+"'>点击激活</a></h3></body></html>\n", true);
            helper.setTo("2424032020@qq.com");
            helper.setFrom("18137232373@163.com");
            mailSender.send(message);
            System.out.println("发送成功");
        } catch (MailException e) {
            e.printStackTrace();
            System.out.println("发送失败");
        } catch (MessagingException e) {
            e.printStackTrace();
        }
    }

}
